#include "stdafx.h"
#include "BrushView.h"

CxBrushView::CxBrushView()
    : m_clrBkg(CLR_INVALID)
{}

CxBrushView::~CxBrushView()
{}

HRESULT CxBrushView::GetColor(LPCOLORREF lpClr)
{
    if (!lpClr) return E_POINTER;

    *lpClr = m_clrBkg;

    return S_OK;
}

HRESULT CxBrushView::SetColor(COLORREF clr)
{
    m_clrBkg = clr;
    return S_OK;
}

HRESULT CxBrushView::Paint(IxCanvas* pCanvas)
{
    if (!pCanvas)   return E_POINTER;

    COLORREF clr = m_clrBkg;

    clr += (m_byAlpha << 24);

    CRect rcDraw(m_rcBox);

    if (!m_rcBorder.IsRectNull())
    {
        rcDraw.left += m_rcBorder.left;
        rcDraw.right -= m_rcBorder.right;
        rcDraw.top += m_rcBorder.top;
        rcDraw.bottom -= m_rcBorder.bottom;
    }

    if (!rcDraw.IsRectEmpty())
    {
        pCanvas->FillSolidRect(rcDraw, clr);
    }

#if _DEBUG
    ATLTRACE(L"\n paint times(%d) this(%x) rect(%d, %d, %d, %d)", ++__count, this, m_rcBox.left, m_rcBox.top, m_rcBox.Width(), m_rcBox.Height());
#endif

    return S_OK;
}